package com.work.api.main;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.work.dto.main.*;
import com.work.service.main.IBulkTallyService;
import com.work.vo.main.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 散货外捣控制器
 *
 * @author ：dujianyu
 * @since ：Created in 2024/5/9 10:05
 */
@RestController
@AllArgsConstructor
@RequestMapping("bulkTally")
@Api(value = "散货外捣控制器", tags = "散货外捣控制器")
public class BulkTallyController extends BladeController {

    private IBulkTallyService service;

    @PostMapping("/appSubmit")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "app提交（理货员理货）", notes = "传入dto")
    public R<Boolean> appSubmit(@Valid @RequestBody BulkTallyAppSubmitDTO dto) {
        return R.status(service.submitBulkTally(dto));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> remove(@ApiParam(value = "主键", required = true) @RequestParam String id) {
        return R.status(service.removeBulkTally(Func.toLong(id)));
    }

    @GetMapping("/bulkTallyHistory")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入dto")
    public R<IPage<BulkTallyVO>> selectBulkTallyHistoryPage(BulkTallySearchDTO dto, Query query) {
        IPage<BulkTallyVO> pages = service.selectBulkTallyHistoryPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @GetMapping("/checkPage")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "审核分页", notes = "传入dto")
    public R<IPage<BulkTallyCheckVO>> selectCheckPage(BulkTallySearchDTO dto, Query query) {
        IPage<BulkTallyCheckVO> pages = service.selectCheckPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @PostMapping("/changeIsCheck")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "检算确认", notes = "传入主键ID")
    public R<String> changeIsCheck(@RequestParam String id) {
        return R.data(service.changeIsCheck(id));
    }

    @PostMapping("/correctTon")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "检算修正件吨", notes = "传入主键ID")
    public R<Boolean> correctTon(@RequestBody BulkTallyCorrectSubmitDTO dto) {
        return R.status(service.correctTon(dto));
    }

    @GetMapping("/unlockPage")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "解锁分页", notes = "传入dto")
    public R<IPage<BulkTallyUnlockVO>> selectUnlockPage(BulkTallySearchDTO dto, Query query) {
        IPage<BulkTallyUnlockVO> pages = service.selectUnlockPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @PostMapping("/changeIsEdit")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "检算确认", notes = "传入主键ID")
    public R<String> changeIsEdit(@RequestParam String id) {
        return R.data(service.changeIsEdit(id));
    }

    @GetMapping("/unlockDetail")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "详情", notes = "传入主键ID")
    public R<BulkTallyUnlockDetailVO> selectBulkDetail(BulkTallySearchDTO dto) {
        BulkTallyUnlockDetailVO data = service.selectBulkDetail(dto);
        return R.data(data);
    }

    @GetMapping("/tallySearchExportPage")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "工班查询导出分页", notes = "传入dto")
    public R<IPage<BulkTallySearchExportVO>> selectTallySearchExportPage(BulkTallySearchDTO dto, Query query) {
        IPage<BulkTallySearchExportVO> pages = service.selectTallySearchExportPage(Condition.getPage(query), dto);
        return R.data(pages);
    }

    @GetMapping("/tallySearchExportTotal")
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "工班查询导出数量统计", notes = "传入dto")
    public R<TotalPieceTonVO> tallySearchExportTotal(BulkTallySearchDTO dto) {
        TotalPieceTonVO data = service.selectTallySearchExportTotal(dto);
        return R.data(data);
    }
}
